home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.09 Sep 90 / CursorControl Folder / Functions.c < prev    next >
Encoding:
Text File  |  1989-07-03  |  3.3 KB  |  231 lines  |  [TEXT/KAHL]

  1.  
  2. /****
  3.  * GetEText()
  4.  *
  5.  * Get text of an ETItem
  6.  *
  7.  ****/
  8.  
  9. GetEText (theDialog, theItem, s)
  10. DialogPtr    theDialog;
  11. int            theItem;
  12. char        *s;
  13. {
  14.     int     theType;
  15.     Handle    Hdl;
  16.     Rect    box;
  17.  
  18.     GetDItem (theDialog, theItem, &theType, &Hdl, &box);
  19.     GetIText (Hdl, s);
  20. }
  21. /* end GetEText */
  22.  
  23.  
  24. /****
  25.  * GetETNum()
  26.  *
  27.  * Get number from an ETItem
  28.  *
  29.  ****/
  30.  
  31. GetETNum(theDialog, theItem)
  32. DialogPtr    theDialog;
  33. int            theItem;
  34. {
  35.     Str255    s;
  36.     long    theNum;
  37.     
  38.     GetEText(theDialog, theItem, &s);
  39.     StringToNum(s, &theNum);
  40.     return(theNum);
  41. }
  42. /* end GetETNum */
  43.  
  44.  
  45. /****
  46.  * SetEText()
  47.  *
  48.  * Set text of an ETItem
  49.  *
  50.  ****/
  51.  
  52. SetEText (theDialog, theItem, s)
  53. DialogPtr    theDialog;
  54. int            theItem;
  55. Str255        s;
  56. {
  57.     int     theType;
  58.     Handle    Hdl;
  59.     Rect    box;
  60.  
  61.     GetDItem (theDialog, theItem, &theType, &Hdl, &box);
  62.     SetIText (Hdl, s);
  63. }
  64. /* end SetEText */
  65.  
  66.  
  67. /****
  68.  * SetETNum()
  69.  *
  70.  * Set number in an ETItem
  71.  *
  72.  ****/
  73.  
  74. SetETNum(theDialog, theItem, theNum)
  75. DialogPtr    theDialog;
  76. int            theItem;
  77. long        theNum;
  78. {
  79.     Str255    s;
  80.     
  81.     NumToString(theNum, s);
  82.     SetEText(theDialog, theItem, &s);
  83. }
  84. /* end GetETNum */
  85.  
  86.  
  87. /*****
  88.  * LToGRect()
  89.  *
  90.  * Convert a local rect to global
  91.  *
  92.  *****/
  93.  
  94. LToGRect(r)
  95. Rect    *r;
  96. {
  97.     Point    pt1,
  98.             pt2;
  99.  
  100.     pt1 = topLeft(*r);
  101.     pt2 = botRight(*r);
  102.     LocalToGlobal(&pt1);
  103.     LocalToGlobal(&pt2);
  104.     Pt2Rect(pt1, pt2, r);
  105. }
  106. /* end LToGRect */
  107.  
  108.  
  109. /*****
  110.  * CenterWindowPoint()
  111.  *
  112.  * Calculates the topleft co-ords of a window,
  113.  * taking screen size into account
  114.  *
  115.  *****/
  116.  
  117. Point
  118. CenterWindowPoint (theRect)
  119. Rect    *theRect;
  120.  
  121. {
  122.     int            theInd = (screenBits.bounds.bottom<350) ? 3:4;
  123.     Point        thePt;
  124.     int            int1,
  125.                 int2;
  126.  
  127.     int1=((screenBits.bounds.right-screenBits.bounds.left-theRect->right+theRect->left) / 2);
  128.     int2=((screenBits.bounds.bottom-screenBits.bounds.top-theRect->bottom+theRect->top+20) / theInd);
  129.     SetPt(&thePt, int1, int2);
  130.     return(thePt);
  131. }
  132. /* end CenterWindowPoint */
  133.  
  134.  
  135. /*****
  136.  * CenterWindow()
  137.  *
  138.  * Centers a dialog or window
  139.  *
  140.  *****/
  141.  
  142. void
  143. CenterWindow(theDialog)
  144. DialogPtr    theDialog;
  145. /*  Center window - center slightly higher for large screens */
  146. {
  147.     Point    thePt;
  148.     Rect    newBounds;
  149.  
  150.     newBounds = *&theDialog->portRect;
  151.     LToGRect(&newBounds);
  152.     thePt = CenterWindowPoint(&newBounds);
  153.     MoveWindow(theDialog, thePt.h, thePt.v, 0);
  154. }
  155. /* end CenterWindow */
  156.  
  157.  
  158. /****
  159.  * ClickButton()
  160.  *
  161.  * Simulate a click in a button
  162.  *
  163.  ****/
  164.  
  165. ClickButton(theDialog, ID, method) /* 0 is off, 1 is on, 2 simulates a click */
  166. DialogPtr        theDialog;
  167. int                ID;
  168. int                method;
  169. {
  170.     int        itemType;
  171.     Handle    item;
  172.     Rect    box;
  173.     long    ticks;
  174.  
  175.     GetDItem(theDialog, ID, &itemType, &item, &box);
  176.     HiliteControl((ControlHandle) item, (method >= 1));
  177.     if (method >= 2)
  178.         {
  179.             Delay(8L, &ticks);
  180.             HiliteControl((ControlHandle) item, 0);
  181.         }
  182. }
  183. /* end ClickButton */
  184.  
  185.  
  186. /****
  187.  * FrameItem()
  188.  *
  189.  * Frame a dialog item in current pen modes
  190.  *
  191.  ****/
  192.  
  193. void
  194. FrameItem (theDialog, item)
  195. DialogPtr    theDialog;
  196. int            item;
  197. {
  198.     int            optType;
  199.     Handle        btnHdl;
  200.     Rect        optBox;
  201.  
  202.     SetPort(theDialog);
  203.     GetDItem(theDialog, item, &optType, &btnHdl, &optBox);
  204.     FrameRect(&optBox);
  205. }
  206. /* end FrameItem */
  207.  
  208.  
  209. /****
  210.  * DrawDefaultBtn()
  211.  *
  212.  * Outline the default button
  213.  *
  214.  ****/
  215.  
  216. void
  217. DrawDefaultBtn (theDialog, item)
  218. DialogPtr    theDialog;
  219. int            item;
  220. {
  221.     int            optType;
  222.     Handle        btnHdl;
  223.     Rect        optBox;
  224.  
  225.     SetPort(theDialog);
  226.     GetDItem(theDialog, item, &optType, &btnHdl, &optBox);
  227.     PenSize(3, 3);
  228.     InsetRect(&optBox, -4, -4);
  229.     FrameRoundRect(&optBox, 16, 16);
  230. }
  231. /* end DrawDefaultBtn */